package com.migo.service.impl;

import com.migo.dao.MaterialDao;
import com.migo.dao.MaterialDTODao;
import com.migo.entity.MaterialDTOEntity;
import com.migo.entity.MaterialEntity;
import com.migo.service.MaterialService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;


@Service("materialService")
public class MaterialServiceImpl implements MaterialService {
    @Autowired
    private MaterialDao materialDao;

    @Autowired
    private MaterialDTODao materialDTODao;

    @Override
    public MaterialEntity queryObject(String id) {
        return materialDao.queryObject(id);
    }

    @Override
    public List<MaterialEntity> queryList(Map<String, Object> map) {

        return materialDao.queryList(map);
    }

    @Override
    public List<MaterialDTOEntity> queryMaterialList(Map<String, Object> map) {
        List<MaterialDTOEntity> result = new ArrayList<MaterialDTOEntity>() {
        };
        if(map.containsKey("lang")){
            if("zh_cn".equals(map.get("lang"))  || "zh".equals(map.get("lang")) || "ZH".equals(map.get("lang"))){
                result=  materialDTODao.queryMaterialListZH(map);
            }else{
                result=  materialDTODao.queryMaterialListEN(map);
            }
        }else{
            result = materialDTODao.queryMaterialListEN(map);
        }
        //result = materialDTODao.queryMaterialListAll(map);
        return result;
    }

    @Override
    public int queryMaterialListTotal(Map<String, Object> map) {
        return materialDTODao.queryMaterialListTotal(map);
    }

    @Override
    public int queryTotal(Map<String, Object> map) {
        return materialDao.queryTotal(map);
    }

    @Override
    public void save(MaterialEntity material) {
        materialDao.save(material);
    }

    @Override
    public void update(MaterialEntity material) {
        materialDao.update(material);
    }

    @Override
    public void delete(String id) {
        materialDao.delete(id);
    }

    @Override
    public void deleteBatch(String[] ids) {
        materialDao.deleteBatch(ids);
    }

}
